package com.HomeWork;

public class work9_Money {
    boolean f = true;
    double money;

    public work9_Money(double money) {
        this.money = money;
    }

    public synchronized void cunMoney(double Cmoney) {
        if(this.money>1000){
            System.out.println(" 存了点钱，钱拿去花");
            try {
                notify();
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
//        try {
//            Thread.sleep(100);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        money = Cmoney + money;
        System.out.println(Thread.currentThread().getName() + "存了" + Cmoney + "--->" + money);
        //f = true;
       // notifyAll();

    }

    public synchronized void quMoney(double Qmoney) {
        if (money<1000) {
            System.out.println("老公存钱了");
            notifyAll();
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
        money = money - Qmoney;
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "取钱" + Qmoney + "---余额" + this.money);
    }

    public synchronized double yuE() {
        return this.money;
    }
}
